pil durumuna göre konum alma
merhabalar pil durumuma göre konumumu güncellemem lazım ama bir kere konum alıyor ve güncellemiyor hatam nerede acaba yardımcı olabilirseniz sevinirim kolay gelsin iyi çalısmalar
package com.example.ilkdeneme;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.BatteryManager;
import android.os.Bundle;
import android.provider.Telephony.Sms.Conversations;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
public class MainActivity extends Activity{
String context;
LocationManager locationManager;
Location location;
android.location.LocationListener locationListener;
double lat;
double lng;
int level;
private TextView textView1;
private TextView textView3;
private TextView batteryinfo;
private static final long SURE = 1000 * 40; //40 saniye
private static final long SURE1 = 1000 * 100;
private static final long SURE2 = 1000 * 250;
private static final long SURE3 = 1000 * 300;
String bat;
private BroadcastReceiver batteryInfoReceiver=new BroadcastReceiver(){
public void onReceive(Context contex, Intent intent){
level=intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
batteryinfo.setText(""+level);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter ifilter = new IntentFilter ( Intent . ACTION_BATTERY_CHANGED );
Intent batteryStatus = getApplicationContext (). registerReceiver ( null , ifilter );
int status = batteryStatus . getIntExtra ( BatteryManager . EXTRA_LEVEL , - 1 );
bat = String.valueOf(status);
textView1 = (TextView) findViewById(R.id.lat);
textView3 = (TextView) findViewById(R.id.lng);
batteryinfo=(TextView) findViewById(R.id.bat);
this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(context);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateWithNewLocation(location);
//locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0, 0, locationListener);
while(true){
if(level==70 && level<=100)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,SURE, 0, locationListener);
}
if(level==50 && level<=69)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,SURE1, 0, locationListener);
}
if(level==20 && level<=49)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,SURE2, 0, locationListener);
}
if(level==0 && level<=19)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,SURE3, 0, locationListener);
}
}
}
private void updateWithNewLocation(Location location) {
locationListener = new android.location.LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
lat = location.getLatitude();
lng = location.getLongitude();
textView1.setText("" + lat);
textView3.setText("" + lng);
Log.e("lat : ", "" + lat);
Log.e("lng : ", "" + lng);
}
};
}
}